
efform_onload = function ()
{	
}

//查询
button_query_onclick = function(){
	efgrid.submitInqu("ef_grid_result","ZM","ZMCP05","query");
}
//插入
button_insert_onclick = function(){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	efgrid.submitForm("ef_grid_result","ZM","ZMCP05","insert",true);
}
//删除
button_delete_onclick = function(){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)
		return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{	
		
		if(grid.getCellValueByColumnName(rows[i],"fdPlanStatus")!="草拟")
		{
			
			EFAlert("只能对草拟的记录进行删除！"); return;
		}
	}
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm("ef_grid_result","ZM","ZMCP05","delete",true);
	});
}
//修改
button_update_onclick = function(){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdPlanStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行修改！"); return;
		}
	}
	efgrid.submitForm("ef_grid_result","ZM","ZMCP05","update",true);
}
//上报
button_report_onclick = function(){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	if(rows.length > 1) {
		EFAlert("一次只能上报一条记录！"); return;
	}
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdPlanStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行上报！"); return;
		}
	}
	EFConfirm('你确认要上报吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCP05","report",true);
	});
}
//新增行后的回调函数
efgrid_afterAddNewRow = function(grid_id){
		var grid = efgrid.getGridObject("ef_grid_result");
		var rows = grid.getCheckedRows();
		var fdCreator=$('#fdCreator').val();//编制人
		var fdCreateDepartmentId=$('#fdCreateDepartmentId').val();//部门
	    var now = new Date();
	    var year = now.getFullYear();       //年
	    var month = now.getMonth() + 1;     //月
	    if(month > 12) {
	    	month = 1;
	    	year += 1;
	    }
	    if(month < 10) month = "0"+month;
	    var day = now.getDate();            //日 
	    var clock = year + "-" + month + "-";
	    if(day < 10) clock += "0";
	    clock += day;
		for(var i = 0 ; i < rows.length;i++){
			grid.getBlockData().setCell(rows[i], "fdPlanStatus", "草拟");
			grid.getBlockData().setCell(rows[i], "fdPlanYear", year);
			grid.getBlockData().setCell(rows[i], "fdPlanMonth", month);
			grid.getBlockData().setCell(rows[i], "fdCreator", fdCreator);
			grid.getBlockData().setCell(rows[i], "fdPulisher", "");//fdTitle
			grid.getBlockData().setCell(rows[i], "fdTitle", '');
			grid.getBlockData().setCell(rows[i], "fdPlanType", '');
			grid.getBlockData().setCell(rows[i], "fdCreateDepartmentId", fdCreateDepartmentId);
			grid.getBlockData().setCell(rows[i], "fdCreateDate", clock);
			grid.getBlockData().setCell(rows[i], "fdShow", "0");
		}
		for(var i = 0 ; i < rows.length;i++){
			grid.getBlockData().setCell(rows[i], "fdKeyId", "");
		}
}

//单元格编辑后回调的方法 display - value
efgrid_onDataCellSaved = function( grid_id, row_index, col_index, cell_value ) 
{	
	var grid = efgrid.getGridObject("ef_grid_result"); 
	var rows = grid.getCheckedRows(); 
	var fdPlanType = grid.getCellValue(row_index, 3,"fdPlanType")
	var info=_getEi();
	var eiBlock=info.getBlock("cmes.cp.plantype");
	for(var i=0;i<eiBlock.getRows().length;i++)
	{
		var _value = eiBlock.getCell(i,"value");
		if(_value==fdPlanType)
		{	
			var plantype = eiBlock.getCell(i,"display");
			var fdYear = grid.getCellValue(row_index, 1,"fdPlanYear");	
			var fdMonth = grid.getCellValue(row_index, 2,"fdPlanMonth");	
			var fdtitle = fdYear+"年"+fdMonth+"月"+plantype;
			grid.setCellValue(row_index, 4, fdtitle , TYPE_DATA);
			grid.refreshCell( row_index, 4 , TYPE_DATA );
		}
	}
}

/**----------------------------从这里往下的方法都是附件操作相关方法------------------
 */
button_upload_onclick=function(){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return;
	var row_index=grid.getCheckedRowCount();
	var row=grid.getCheckedRows();
	if(row_index>1){
		EFAlert("只能选中一条项目信息后上传！");
		return;
	}
	var docId=grid.getCellValueByColumnName(row,"fdDocid");
	if(!isAvailable(docId)) {
		EFAlert("未指定文档号！", "系统警告");
		return false;
	}
	var url = "DispatchAction.do?efFormEname=EUAF3501";
		url = url + "&inqu_status-0-code=zm.cp";
	
	if(grid.getCellValueByColumnName(row,"fdPlanStatus")!="草拟")
	{
		url = url + "&editFlag=0";
	}else{
		url = url + "&editFlag=1";
	}
	url = url + "&inqu_status-0-docId="+docId+"&time=" + new Date().getTime();
	
	EFColorbox({href:url,title:"附件管理",width:"80%", height:"80%", iframe:true});
}
